<template>
  <div class="app-container">
    <!-- 搜索 -->
    <el-form :model="query" ref="queryForm" :inline="true" class="top-search" label-position="left">
      <el-form-item label="关键词" prop="enterpriseName">
        <el-input v-model="query.enterpriseName" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList()">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作菜单 -->
    <div class="mid-action">
      <div>
        <!-- <el-button type="primary" size="mini" @click="creatItem('creat')">添加</el-button> -->
      </div>
    </div>
    <!-- 表格列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="缩略图" align="center" prop="companyPicture" width="140px">
        <template slot-scope="scope">
          <el-image :src="scope.row.companyPicture" fit="cover" style="width:120px;height:80px;"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="公司名" align="center" prop="enterpriseName" />
      <el-table-column label="行业" align="center" prop="industryInvolved" />
      <el-table-column label="联系人" align="center" prop="wxName" />
      <el-table-column label="手机号" align="center" prop="wxPhone" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="状态" align="center" prop="createTime">
        <template slot-scope="scope">
          <span v-if="scope.row.sign == 0">待审核</span>
          <span v-else-if="scope.row.sign == 1">已通过</span>
          <span v-else-if="scope.row.sign == 2">已拒绝</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-if="scope.row.sign == 0" @click="statusShow(scope.row)">审核</el-button>
          <el-button size="mini" type="text" v-else-if="scope.row.sign == 1" @click="statusShow(scope.row)">撤销审核</el-button>
          <el-button size="mini" type="text" v-else-if="scope.row.sign == 2" @click="statusShow(scope.row)">重审</el-button>
          <el-button size="mini" type="text" @click="route(scope.row)">发布文章</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList()"
    />
    <!-- 审核 -->
    <el-dialog title="审核" :visible.sync="statusFormShow">
      <el-form class="edit_form" :model="form" ref="form" label-width="100px" label-position="right">
        <el-form-item label="公司名">
          <el-input v-model="form.enterpriseName" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="企业简介">
          <el-input v-model="form.companyProfile" type="textarea" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="行业">
          <el-input v-model="form.industryInvolved" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="form.site" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="营业执照">
          <el-image class="avatar" :src="form.businessLicense" :preview-src-list="[form.businessLicense]"></el-image>
        </el-form-item>
        <el-form-item label="企业照片">
          <el-image class="avatar" :src="form.companyPicture" :preview-src-list="[form.companyPicture]"></el-image>
        </el-form-item>
        <el-form-item label="联系人">
          <el-input v-model="form.wxName" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="头像">
          <el-image class="avatar" :src="form.wxPortrait"></el-image>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="form.wxPhone" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="职位">
          <el-input v-model="form.post" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="微信二维码">
          <el-image class="avatar" :src="form.wxNumber" :preview-src-list="[form.wxNumber]"></el-image>
        </el-form-item>
        <el-form-item label="个人名片">
          <el-image class="avatar" :src="form.businessCard" :preview-src-list="[form.businessCard]"></el-image>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-input v-model="form.createTime" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="审核结果" prop="sign">
          <el-radio-group v-model="form.sign" size="small">
            <el-radio :label="1" border>通过</el-radio>
            <el-radio :label="2" border>拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="statusChange()">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getCompanyList, updateCompanyStatus } from "@/api/eh-api";
export default {
  data() {
    return {
        //审核
        statusFormShow:false,
        form:{
          id:'',
          sign: 1, //1通过 2拒绝
        },
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 查询参数
        query: {
            pageNum: 1,
            pageSize: 10,
            enterpriseName: undefined,
        },
        list:[],
    };
  },
  created() {
    this.getList()
  },
  methods: {
    /**
     * 接口 - 获取列表
     */
    getList() {
      this.loading = true;
      getCompanyList(this.query).then(({ rows, total }) => {
        this.list = rows;
        this.total = parseInt(total);
        this.loading = false;
        this.ids = [];
      })
      .catch(() => {
        this.loading = false;
      });
    },

    /**
     * 事件 - 打开审核表单
     */
    statusShow:function(row){
        this.statusFormShow = true
        this.form = row
    },

    /**
     * 接口 - 审核表单提交
     */
    statusChange:function(){
      console.log(this.form)
      updateCompanyStatus(this.form).then( res => {
        if( res.code == 200 ){
          this.$message({
            message: '修改成功',
            type: 'success'
          });
          this.statusFormShow = false
          this.getList();
        }else{
          this.$message.error(res.msg);
        }
      })
    },

    /**
     * 统一路由
     */
    route(row) {
      console.log(row)
      this.$router.push({ path: '/material/article/creat', query: { enterpriseId:row.id } })
    },

  },
};
</script>

<style lang="scss" scoped>
.mid-action {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  align-items: center;
  .total {
    background-color: rgba(65, 133, 244, 0.1);
    border: 1px solid rgba(65, 133, 244, 0.2);
    border-radius: 3px;
    font-size: 14px;
    min-height: 32px;
    line-height: 32px;
    padding: 0 12px;
    color: #606266;
  }
  .num {
    color: #00f;
  }
}
.thumbnail {
  width: 160px;
  height: 80px;
}
.input{
  width: 80%;
}

/**头像 */
.avatar-uploader /deep/.el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.avatar-uploader /deep/.el-upload:hover {
    border-color: #409EFF;
}
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 128px;
    height: 128px;
    line-height: 128px;
    text-align: center;
}
.avatar {
    width: 128px;
    height: 128px;
    display: block;
}
</style>
